﻿Imports BUS
Imports DAO
Imports DTO

Public Class FormDanhSachHoaDon

    Private flag As Integer = 0

    Private Sub ButtonThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonThoat.Click
        Me.Close()
    End Sub

    Private Sub FormQuanLyHoaDOn_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadHoaDon()
        dgvHoaDon.ClearSelection()
        flag = 1
    End Sub

#Region "Hàm load hóa đơn"
    Public Sub LoadHoaDon()
        Dim tb As DataTable = HoaDon_BUS.LoadHoaDon()
        dgvHoaDon.DataSource = tb
        dgvHoaDon.Columns(0).Visible = False
        dgvHoaDon.Columns(1).HeaderText = "Tên khách hàng"
        dgvHoaDon.Columns(2).HeaderText = "CMND"
        dgvHoaDon.Columns(3).HeaderText = "Ngày lập"
        dgvHoaDon.Columns(4).HeaderText = "Tổng tiền"
    End Sub
#End Region


#Region "Hàm chọn hóa đơn hiện chi tiết hóa đơn"
    Private Sub dgvHoaDon_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgvHoaDon.SelectionChanged
        If flag = 1 Then
            Dim ma As Integer = Integer.Parse(dgvHoaDon.CurrentRow.Cells(0).Value)
            Dim tb As DataTable = HoaDon_BUS.LoadPhieuNhapTheoMa(ma)
            dgvChiTiet.DataSource = tb
            dgvChiTiet.Columns(0).HeaderText = "Tên Sách"
            dgvChiTiet.Columns(1).HeaderText = "Số Lượng"
            dgvChiTiet.Columns(2).HeaderText = "Đơn Giá"
            dgvChiTiet.Columns(3).HeaderText = "Thành Tiền"
        End If
    End Sub
#End Region

End Class